<?php
require_once("model/loginBD.php");
function add_subscriptionBD($id_user) {
	$query = "INSERT INTO subscription (id_user,id_subscriber) 
			  VALUES ( '".$_SESSION['id_user']."','".$id_user."' )";
	logIn();
	$rs = mysql_query($query); //or die('Erreur SQL !'.$query.'<br>'.mysql_error());
	logOut();
	if (!$rs)
		return false;
	return true;
}

function view_subscriptionBD($id_user) {
	$query = "SELECT id_user, id_subscriber FROM subscription
			  WHERE id_user = '".$_SESSION['id_user']."'
			  AND id_subscriber = '".$id_user."'"; 
			  
	logIn();
	$result = mysql_query($query) or die('Erreur SQL !'.$query.'<br>'.mysql_error());	
	logOut();
	$total = mysql_num_rows($result);
	if($total) {
		
		while($row = mysql_fetch_array($result)) {
			$tab['id_user'][] = $row['id_user'];
			$tab['id_subscriber'][] = $row['id_subscriber'];
			
		}
	}
	if( mysql_num_rows($result) > 0) return $tab;	else return 0;
}

function view_simple_subscriptionBD() {
	$query = "SELECT id_user, id_subscriber FROM subscription
			  WHERE id_user = '".$_SESSION['id_user']."'"; 
			  
	logIn();
	$result = mysql_query($query) or die('Erreur SQL !'.$query.'<br>'.mysql_error());	
	logOut();
	$total = mysql_num_rows($result);
	if($total) {
		
		while($row = mysql_fetch_array($result)) {
			$tab['id_user'][] = $row['id_user'];
			$tab['id_subscriber'][] = $row['id_subscriber'];
			
		}
	}
	if( mysql_num_rows($result) > 0) return $tab;	else return 0;
}

function delete_subscription_db($id_user) {
	$query = "DELETE FROM subscription WHERE (id_user = '".$_SESSION['id_user']."') AND (id_subscriber = '".$id_user."')";
	logIn();
	mysql_query($query) or die('Erreur SQL !'.$query.'<br>'.mysql_error());
	logOut();
	return true;
}

?>